/*
 * @Author: Guiter 1336263157@qq.com
 * @Date: 2023-11-29 19:13:23
 * @LastEditors: Guiter 1336263157@qq.com
 * @LastEditTime: 2023-11-29 20:21:22
 * @FilePath: \nuxt3-music-player\src\utils\transTimes.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

/* 从毫秒转成分钟 */
function transTime(value: number): string {
  // console.log(value);
  let time = '';
  const h = Math.trunc(value / 1000 / 3600);
  // let h = value / 3600
  // value %= 3600;
  const m = Math.trunc(value / 1000 / 60);
  // let m = (value / 60);
  const s = Math.trunc((value / 1000) % 60);
  // let s = (value % 60);
  if (h > 0) {
    time = formatTime(h + ':' + m + ':' + s);
  } else {
    time = formatTime(m + ':' + s);
  }
  return time;
}

// 格式化时间
export function formatTime(value: any): string {
  let time = '';
  const s = value.split(':');
  let i = 0;
  for (; i < s.length - 1; i++) {
    time += s[i].length === 1 ? '0' + s[i] : s[i];
    time += ':';
  }
  time += s[i].length === 1 ? '0' + s[i] : s[i];
  return time;
}

export default transTime;
